import logging

from pylons import config, request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect

from papyrus.lib.base import BaseController, render
from papyrus.model import meta, Article

log = logging.getLogger(__name__)


class BlogController(BaseController):

    def index(self):
        # Return a rendered template
        #return render('/blog.mako')
        # or, return a response

        # How many posts per page ?
        ppp = config["papyrus.config"].get('general', 'posts_per_page')

        q = meta.Session.query(Article)
        q = q.filter_by(is_published=True)
        q = q.order_by(Article.creation_date.desc())
        q = q.limit(ppp)
        c.articles = q.all()

        return render('/blog/index.mako')
